<template>
	<div class="subtitie">
		<ul>
			<template v-for="message in subTitleData">
				<li :key="message.id" v-if="message.data.length <= 100">
					<span :class="message.from === clientId ? 'customer-label' : 'agent-label'">{{ message.from === clientId ? '访客：' : '客服：' }}</span>
					<span>{{ message.data }}</span>
				</li>
				<li :key="message.id" v-else :id="message.id">
					<span :class="message.from === clientId ? 'customer-label' : 'agent-label'">{{ message.from === clientId ? '访客：' : '客服：' }}</span>
					<span>{{ message.data }}</span>
				</li>
			</template>
		</ul>
	</div>
</template>

<script>
export default {
	props: {
		subTitleData: {
			type: Array,
			default: () => []
		},
		clientId: {
			type: String,
			default: () => ''
		}
	},
	computed: {},

	data() {
		return {};
	},
	methods: {},
	beforeDestroy() {
		this.subTitleData.forEach(item => {
			if (item.interval) {
				clearInterval(item.interval);
			}
		});
	}
};
</script>

<style scoped lang="less">
.subtitie ul {
	margin: 0 auto;
	display: flex;
	align-items: baseline;
	flex-flow: column;
	width: 90%;
	position: relative;
}
.subtitie ul li {
	width: auto;
	float: left;
	text-align: justify;
	letter-spacing: -0.02em;
	background: #333333;
	border-radius: 4px;
	opacity: 0.5617;
	color: #fff;
	font-size: 16px;
	padding: 10px;
	max-height: 140px;
	overflow-y: hidden;
	position: relative;
	margin: 10px 0;
	word-break: break-all;
	.agent-label {
		padding-left: 8px;
		display: inline-block;
		color: #ff7845;
		white-space: nowrap;
		width: 60px;
	}
	.customer-label {
		padding-left: 8px;
		display: inline-block;
		color: #98daff;
		white-space: nowrap;
		width: 60px;
	}
}
</style>
